package shujia.day12.homework;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
    1.     假如有以下email数据“aa@sohu.com,bb@163.com,cc@sina.com,.. ”
    现需要把email 中的用户部分和邮件地址部分分离，分离后以键值对应的方式放入HashMap？
 */
public class Test3 {
    public static void main(String[] args) {
        String s1 = "aa@sohu.com,bb@163.com,cc@sina.com";

        HashMap<String, String> map1 = new HashMap<>();

        String[] userInfo = s1.split(",");
//        System.out.println(Arrays.toString(userInfo));

        for (String email : userInfo) {
            //aa@sohu.com
            String[] res1 = email.split("@");
            String userName = res1[0];
            String address = res1[1];
            map1.put(userName,address);
        }

        Set<Map.Entry<String, String>> entries = map1.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String ad = entry.getValue();
            System.out.println(key+"-"+ad);
        }

    }
}
